/*
 * 创建工作流节点时默认提供名称
 */
function putDefaultValue(scope,item){
	var timestamp=new Date().getTime();
	function setValue(properties,item,number){
		for(var i = 0;i<properties.length;i++){
			var prop = properties[i]
			switch (prop.title)
			{
				case "ID":
					prop.value = item.id + timestamp;
					break;
				case "名称":
					prop.value = item.name + number;
					break;
				case "描述":
					prop.value = item.description;
					break;
				default :
					continue;
			}
			scope.updatePropertyInModel(prop);
		}
	}
	
	switch (item.id)
	{
		case "StartNoneEvent"://开始事件
			setValue(scope.selectedItem.properties,item,ACTIVITI.CONFIG.StartNoneEvent);
			ACTIVITI.CONFIG.StartNoneEvent++;
			break;
		case "StartTimerEvent"://开始事件
			setValue(scope.selectedItem.properties,item,ACTIVITI.CONFIG.StartTimerEvent);
			ACTIVITI.CONFIG.StartTimerEvent++;
			break;
		case "UserTask"://用户任务
			setValue(scope.selectedItem.properties,item,ACTIVITI.CONFIG.UserTask);
			ACTIVITI.CONFIG.UserTask++;
			break;
		case "ScriptTask"://脚本任务
			setValue(scope.selectedItem.properties,item,ACTIVITI.CONFIG.ScriptTask);
			ACTIVITI.CONFIG.ScriptTask++;
			break;
		case "CallActivity"://调用活动(子流程)
			setValue(scope.selectedItem.properties,item,ACTIVITI.CONFIG.CallActivity);
			ACTIVITI.CONFIG.CallActivity++;
			break;
		case "ExclusiveGateway"://单一网关
			setValue(scope.selectedItem.properties,item,ACTIVITI.CONFIG.ExclusiveGateway);
			ACTIVITI.CONFIG.ExclusiveGateway++;
			break;
		case "ParallelGateway"://并行网关
			setValue(scope.selectedItem.properties,item,ACTIVITI.CONFIG.ParallelGateway);
			ACTIVITI.CONFIG.ParallelGateway++;
			break;
		case "InclusiveGateway"://包含网关
			setValue(scope.selectedItem.properties,item,ACTIVITI.CONFIG.InclusiveGateway);
			ACTIVITI.CONFIG.InclusiveGateway++;
			break;
		case "EventGateway"://事件网关
			setValue(scope.selectedItem.properties,item,ACTIVITI.CONFIG.EventGateway);
			ACTIVITI.CONFIG.EventGateway++;
			break;
		case "EndNoneEvent"://结束事件
			setValue(scope.selectedItem.properties,item,ACTIVITI.CONFIG.EndNoneEvent);
			ACTIVITI.CONFIG.EndNoneEvent++;
			break;
		case "SequenceFlow"://顺序跳转线
			setValue(scope.selectedItem.properties,item,ACTIVITI.CONFIG.SequenceFlow);
			ACTIVITI.CONFIG.SequenceFlow++;
			break;
		default :
			//alert("错误节点");
	}
	
}


/*
 * 删除节点时触发
 */
function deleteItem(scope){
	var  title = scope.selectedItem.title;
	str = title.replace(/[0-9]/ig,"");
	num = title.replace(/[^0-9]/ig,"");
	switch (str)
	{
		case "开始事件"://开始事件
			if(ACTIVITI.CONFIG.StartNoneEvent - num == 1){
				ACTIVITI.CONFIG.StartNoneEvent = num;
			}
			break;
		case "开始事件(触发器)"://开始事件(触发器)
			if(ACTIVITI.CONFIG.StartTimerEvent - num == 1){
				ACTIVITI.CONFIG.StartTimerEvent = num;
			}
			break;
		case "用户任务"://用户任务
			if(ACTIVITI.CONFIG.UserTask - num == 1){
				ACTIVITI.CONFIG.UserTask = num;
			}
			break;
		case "脚本任务"://脚本任务
			if(ACTIVITI.CONFIG.ScriptTask - num == 1){
				ACTIVITI.CONFIG.ScriptTask = num;
			}
			break;
		case "调用活动(子流程)"://调用活动(子流程)
			if(ACTIVITI.CONFIG.CallActivity - num == 1){
				ACTIVITI.CONFIG.CallActivity = num;
			}
			break;
		case "单一网关"://单一网关
			if(ACTIVITI.CONFIG.ExclusiveGateway - num == 1){
				ACTIVITI.CONFIG.ExclusiveGateway = num;
			}
			break;
		case "并行网关"://并行网关
			if(ACTIVITI.CONFIG.ParallelGateway - num == 1){
				ACTIVITI.CONFIG.ParallelGateway = num;
			}
			break;
		case "包含网关"://包含网关
			if(ACTIVITI.CONFIG.InclusiveGateway - num == 1){
				ACTIVITI.CONFIG.InclusiveGateway = num;
			}
			break;
		case "事件网关"://事件网关
			if(ACTIVITI.CONFIG.EventGateway - num == 1){
				ACTIVITI.CONFIG.EventGateway = num;
			}
			break;
		case "结束事件"://结束事件
			if(ACTIVITI.CONFIG.EndNoneEvent - num == 1){
				ACTIVITI.CONFIG.EndNoneEvent = num;
			}
			break;
		case "顺序跳转线"://顺序跳转线
			if(ACTIVITI.CONFIG.SequenceFlow - num == 1){
				ACTIVITI.CONFIG.SequenceFlow = num;
			}
			break;
		default :
			//alert("删除事件");
	}
}

//初始化ACTIVITI.CONFIG id和名称
function initActivitiConfig(name){
	var  title = scope.selectedItem.title;
	str = title.replace(/[0-9]/ig,"");
	num = title.replace(/[^0-9]/ig,"");
	switch (str)
	{
		case "开始事件"://开始事件
			if(ACTIVITI.CONFIG.StartNoneEvent < num){
				ACTIVITI.CONFIG.StartNoneEvent = num;
			}
			break;
		case "开始事件(触发器)"://开始事件(触发器)
			if(ACTIVITI.CONFIG.StartNoneEvent < num){
				ACTIVITI.CONFIG.StartNoneEvent = num;
			}
			break;
		case "用户任务"://用户任务
			if(ACTIVITI.CONFIG.UserTask < num){
				ACTIVITI.CONFIG.UserTask = num;
			}
			break;
		case "脚本任务"://脚本任务
			if(ACTIVITI.CONFIG.ScriptTask < num){
				ACTIVITI.CONFIG.ScriptTask = num;
			}
			break;
		case "调用活动(子流程)"://调用活动(子流程)
			if(ACTIVITI.CONFIG.CallActivity < num){
				ACTIVITI.CONFIG.CallActivity = num;
			}
			break;
		case "单一网关"://单一网关
			if(ACTIVITI.CONFIG.ExclusiveGateway < num){
				ACTIVITI.CONFIG.ExclusiveGateway = num;
			}
			break;
		case "并行网关"://并行网关
			if(ACTIVITI.CONFIG.ParallelGateway < num){
				ACTIVITI.CONFIG.ParallelGateway = num;
			}
			break;
		case "包含网关"://包含网关
			if(ACTIVITI.CONFIG.InclusiveGateway < num){
				ACTIVITI.CONFIG.InclusiveGateway = num;
			}
			break;
		case "事件网关"://事件网关
			if(ACTIVITI.CONFIG.EventGateway < num){
				ACTIVITI.CONFIG.EventGateway = num;
			}
			break;
		case "结束事件"://结束事件
			if(ACTIVITI.CONFIG.EndNoneEvent < num){
				ACTIVITI.CONFIG.EndNoneEvent = num;
			}
			break;
		default :
			//alert("删除事件");
	}
}
